interpol.stw <- function(t, y) {

  ### Linear interpolation 
  ### Implicit assumption: y given on grid 1:m 

  ### Paul Eilers, 2002
  ### Translation to R: Jan Gerretzen, 2009

  if (is.vector(y)) {
    y <- t(as.matrix(y))
  }

  if (is.vector(t)) {
    t <- t(as.matrix(t))
  }

  m <- ncol(y)
  s <- which(1<t & t<m)
  ti <- floor(t[s])
  tr <- t[s] - ti
  f <- matrix(0, nrow(y), length(ti))

  for (i in 1:nrow(y)) {
    g <- y[i, ti + 1] - y[i, ti]
    f[i, ] <- y[i, ti] + tr * g
  }

  list(z=f, sel=s, g=g)
}
